package com.jues.huichain.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.alibaba.android.arouter.launcher.ARouter;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Objects;

import cn.jpush.android.api.JPushInterface;
import health.lm.com.router.ARouterConstant;

/**
 * Created by Android Studio .
 * 作者：zhong
 * 日期：2019/3/1
 * 邮箱：15206394364@163.com
 * 介绍：
 * 修订：====================
 */
public class JPushReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle bundle = intent.getExtras();
        String data = bundle != null ? bundle.getString(JPushInterface.EXTRA_EXTRA) : "";
        // title 这就是一个url，后台约定好的 jpush_url
        //Log.e("极光推送链接", title == null ? "null" : title);
        if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
            //ToastUtils.showLong("[MyReceiver] 用户点击打开了通知");
            Log.d("极光推送链接", "[MyReceiver] 用户点击打开了通知");
            if (Objects.equals(data, "")) {
                return;
            }
            try {
                JSONObject jsonObject = new JSONObject(data);
                /*1 线上， 2 线下*/
                String type = jsonObject.getString("type") != null ? jsonObject.getString("type") : "";
                //ARouter.getInstance().build(Router.MerchantActivity).withString("topbar_title", "").navigation();
                ARouter.getInstance().build(ARouterConstant.MallNoticeActivity).navigation();
//                if (type.equals("1"))
//                    ARouter.getInstance().build(Router.OrderListActivity).withInt("pos", 1).navigation();
//                if (type.equals("2"))
//                    ARouter.getInstance().build(Router.OfflineOrderListActivity).navigation();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }
}
